#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("ans.txt","w",stdout);
	int n;
	int x1,x2,y1,y2,z1,z2,a[3],k,i=0,z;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x1>>x2>>y1>>y2>>z1>>z2>>a[0]>>a[1]>>a[2]>>k;
		for(int i=0;i<k;i++){
			if(i%3==0){
				x1+=a[0];
			}
			else if(i%3==1){
				y1+=a[1];
			}
			else{
				z1+=a[2];
			}
		}
		z=z1;
		while(1){
			if(z<=0){
				cout<<-1<<endl;
				break;
			}
			if(x1-y2>=0){
				z2-=(x1-y2);
			}
			if(z2<=0){
				cout<<z1-(i*(x2-y1))<<endl;
				break;	
			}
			if(x1-y2>=0){
				z-=(x2-y1);
			}
			i++;
		}
	}
	//fclose(stdin);
	//fclose(stdout);
}
